package com.hl.web;

import com.hl.pojo.Courses;
import com.hl.service.SelectCourseLifeService;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/SelectCourse")
public class SelectCourseLifeController {
    @Autowired
    private SelectCourseLifeService selectCourseLifeService;
    @RequestMapping("/selectCourseLife")
    public GeneralResult SelectCourseLife(@RequestBody Map<String,Integer> map1){
//        @RequestBody Map<String,Integer> map1
        Integer value;
        List<Courses> list = null;
        value = map1.get("value");
        switch(value){
            case 0:{
                list = selectCourseLifeService.SelectCourseLifeAll();
                break;
            }
            case 4 :
                //语句
                list =  selectCourseLifeService.SelectCourseLifeAsc();
                break; //可选
            case 5 :
                //语句
                list = selectCourseLifeService.SelectCourseLifeDesc();
                break; //可选
        }
//        if (value == 4) {
//            list =  selectCourseLifeService.SelectCourseLifeAsc();
//        }
//        if (value == 5) {
//            list = selectCourseLifeService.SelectCourseLifeDesc();
//        }
        System.out.println(list);
        System.out.println(value);
        return GeneralResult.success(list);

    }

    @RequestMapping("/selectCourseLife1")
    public GeneralResult SelectCourseLiatMany(@RequestBody Map<String,Integer> map1){
        Double min = null;
        Double max = null;
        Integer num = null;
        Integer value = map1.get("value");
        System.out.println(map1);
        if (value == 6) {
            min = 0.0;
            max = 0.0;
        } else if (value == 7) {
            min = 0.0;
            max = 50.0;
        }else if (value == 8) {
            min = 50.0;
            max = 100.0;
        }else if (value == 9) {
            min = 100.0;
            max = 500.0;
        }else if (value == 10) {
            min = 500.0;
            max = 1000.0;
        }else if (value == 11) {
            min = 1000.0;
            max = null;
        }else if (value == 4) {
            num = 4;
        }else if (value == 5) {
            num = 5;
        }
        List<Courses> list = selectCourseLifeService.SelectCourseLiatMany(map1.get("value"),max,min);
        return GeneralResult.success(list);
    }
}
